<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>价格数据显示测试</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
        }
        .header h1 {
            color: #333;
            margin-bottom: 10px;
        }
        .test-section {
            margin-bottom: 30px;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 8px;
            border-left: 4px solid #1890ff;
        }
        .test-section h3 {
            margin-top: 0;
            color: #333;
        }
        .price-display {
            background: #fff;
            border: 1px solid #d9d9d9;
            border-radius: 8px;
            padding: 20px;
            margin: 15px 0;
        }
        .price-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 0;
            border-bottom: 1px solid #f0f0f0;
        }
        .price-item:last-child {
            border-bottom: none;
        }
        .price-label {
            font-size: 14px;
            color: #666;
        }
        .price-value {
            font-size: 16px;
            color: #ff4d4f;
            font-weight: 600;
        }
        .test-button {
            background: #1890ff;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        .test-button:hover {
            background: #40a9ff;
        }
        .log {
            background: #f5f5f5;
            border: 1px solid #d9d9d9;
            border-radius: 6px;
            padding: 15px;
            font-family: 'Courier New', monospace;
            font-size: 12px;
            max-height: 200px;
            overflow-y: auto;
            white-space: pre-wrap;
        }
        .status {
            margin-top: 20px;
            padding: 15px;
            border-radius: 6px;
            font-size: 14px;
        }
        .status.success {
            background: #f6ffed;
            border: 1px solid #b7eb8f;
            color: #52c41a;
        }
        .status.error {
            background: #fff2f0;
            border: 1px solid #ffccc7;
            color: #ff4d4f;
        }
        .status.info {
            background: #e6f7ff;
            border: 1px solid #91d5ff;
            color: #1890ff;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>💰 价格数据显示测试</h1>
            <p>测试dan页面到zhi页面的价格数据传递和显示</p>
        </div>

        <div class="test-section">
            <h3>📊 模拟dan页面数据</h3>
            <div class="price-display">
                <div class="price-item">
                    <span class="price-label">新冠预防中药 (正常人群) 1剂</span>
                    <span class="price-value">¥10.08</span>
                </div>
                <div class="price-item">
                    <span class="price-label">新冠预防中药 (体弱人群) 1剂</span>
                    <span class="price-value">¥11.80</span>
                </div>
                <div class="price-item">
                    <span class="price-label">新冠预防中药 (儿童人群) 1剂</span>
                    <span class="price-value">¥9.80</span>
                </div>
                <div class="price-item" style="border-top: 2px solid #ff4d4f; margin-top: 10px; padding-top: 15px;">
                    <span class="price-label" style="font-weight: 600; color: #333;">总金额</span>
                    <span class="price-value" style="font-size: 18px;">¥31.68</span>
                </div>
            </div>
        </div>

        <div class="test-section">
            <h3>🔄 数据传递测试</h3>
            <button class="test-button" onclick="testDataPassing()">测试数据传递</button>
            <button class="test-button" onclick="testLocalStorage()">测试本地存储</button>
            <button class="test-button" onclick="testPriceDisplay()">测试价格显示</button>
            <button class="test-button" onclick="clearLog()">清空日志</button>
        </div>

        <div class="test-section">
            <h3>📱 模拟zhi页面显示</h3>
            <div class="price-display">
                <div class="price-item">
                    <span class="price-label">订单编号</span>
                    <span class="price-value" id="orderNumber">-</span>
                </div>
                <div class="price-item">
                    <span class="price-label">下单时间</span>
                    <span class="price-value" id="orderTime">-</span>
                </div>
                <div class="price-item" style="border-top: 2px solid #ff4d4f; margin-top: 10px; padding-top: 15px;">
                    <span class="price-label" style="font-weight: 600; color: #333;">支付金额</span>
                    <span class="price-value" style="font-size: 18px;" id="paymentAmount">-</span>
                </div>
            </div>
            
            <div style="margin-top: 20px;">
                <h4>支付方式选择</h4>
                <div class="price-display">
                    <div class="price-item">
                        <span class="price-label">自费支付 (支付宝/微信)</span>
                        <span class="price-value" id="selfPayAmount">-</span>
                    </div>
                    <div class="price-item">
                        <span class="price-label">医保支付 (医保卡扣费)</span>
                        <span class="price-value" id="insuranceAmount">-</span>
                    </div>
                </div>
            </div>
        </div>

        <div id="status"></div>
        <div class="log" id="log"></div>
    </div>

    <script>
        // 模拟dan页面的订单数据
        const mockDanOrderData = {
            orderNo: `DAN${Date.now()}`,
            items: [
                {
                    id: 'product1',
                    name: '新冠预防中药 (正常人群) 1剂',
                    price: 10.08,
                    quantity: 1
                },
                {
                    id: 'product2',
                    name: '新冠预防中药 (体弱人群) 1剂',
                    price: 11.80,
                    quantity: 1
                },
                {
                    id: 'product3',
                    name: '新冠预防中药 (儿童人群) 1剂',
                    price: 9.80,
                    quantity: 1
                }
            ],
            totalAmount: 31.68,
            createdAt: new Date().toISOString()
        };

        function log(message) {
            const logElement = document.getElementById('log');
            const timestamp = new Date().toLocaleTimeString();
            logElement.textContent += `[${timestamp}] ${message}\n`;
            logElement.scrollTop = logElement.scrollHeight;
        }

        function showStatus(message, type = 'info') {
            const statusElement = document.getElementById('status');
            statusElement.innerHTML = `<div class="status ${type}">${message}</div>`;
        }

        function testDataPassing() {
            log('=== 测试数据传递 ===');
            log('模拟dan页面创建订单数据...');
            log(`订单数据: ${JSON.stringify(mockDanOrderData, null, 2)}`);
            
            // 模拟跳转到zhi页面并传递数据
            log('模拟跳转到zhi页面...');
            log('通过location.state传递订单数据');
            
            // 模拟zhi页面接收数据
            const receivedOrder = mockDanOrderData;
            log('zhi页面接收到的数据:');
            log(`- 订单号: ${receivedOrder.orderNo}`);
            log(`- 总金额: ${receivedOrder.totalAmount}`);
            log(`- 创建时间: ${receivedOrder.createdAt}`);
            
            showStatus('✅ 数据传递测试完成', 'success');
        }

        function testLocalStorage() {
            log('=== 测试本地存储 ===');
            
            try {
                // 保存到localStorage
                localStorage.setItem('danPendingOrder', JSON.stringify(mockDanOrderData));
                log('订单数据已保存到localStorage');
                
                // 从localStorage读取
                const storedData = localStorage.getItem('danPendingOrder');
                const parsedData = JSON.parse(storedData);
                log('从localStorage读取的数据:');
                log(`- 订单号: ${parsedData.orderNo}`);
                log(`- 总金额: ${parsedData.totalAmount}`);
                
                showStatus('✅ 本地存储测试完成', 'success');
            } catch (error) {
                log(`❌ 本地存储测试失败: ${error.message}`);
                showStatus('❌ 本地存储测试失败', 'error');
            }
        }

        function testPriceDisplay() {
            log('=== 测试价格显示 ===');
            
            // 模拟zhi页面的数据处理
            const orderInfo = {
                orderNumber: mockDanOrderData.orderNo,
                orderTime: new Date(mockDanOrderData.createdAt).toLocaleString(),
                paymentAmount: mockDanOrderData.totalAmount
            };
            
            log('处理后的订单信息:');
            log(`- 订单号: ${orderInfo.orderNumber}`);
            log(`- 下单时间: ${orderInfo.orderTime}`);
            log(`- 支付金额: ${orderInfo.paymentAmount}`);
            
            // 更新页面显示
            document.getElementById('orderNumber').textContent = orderInfo.orderNumber;
            document.getElementById('orderTime').textContent = orderInfo.orderTime;
            document.getElementById('paymentAmount').textContent = `¥${orderInfo.paymentAmount.toFixed(2)}`;
            document.getElementById('selfPayAmount').textContent = `¥${orderInfo.paymentAmount.toFixed(2)}`;
            document.getElementById('insuranceAmount').textContent = `¥${orderInfo.paymentAmount.toFixed(2)}`;
            
            log('页面显示已更新');
            showStatus('✅ 价格显示测试完成', 'success');
        }

        function clearLog() {
            document.getElementById('log').textContent = '';
            document.getElementById('status').innerHTML = '';
        }

        // 页面加载完成后的初始化
        window.onload = function() {
            log('价格数据显示测试页面已加载');
            log('点击测试按钮开始验证数据传递和显示');
        };
    </script>
</body>
</html>

